package com.leyou.lyitem.controller;

import com.leyou.item.pojo.Category;
import com.leyou.lyitem.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping("list")
    public ResponseEntity<List<Category>> queryListByParent(@RequestParam(value = "pid",defaultValue = "0") Long pid){

        List<Category> categoryList = categoryService.queryListByParent(pid);
        if (categoryList == null || categoryList.size() < 1) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
        return ResponseEntity.ok(categoryList);
    }

    @RequestMapping("add")
    public void addCategoryByParent(Category category){
        this.categoryService.addCategoryByParent(category);

    }

    @RequestMapping("delete")
    public void deleteCategoryByParent(@RequestParam("id")Long id){

        int i = this.categoryService.deleteCategoryByParent(id);

    }

    @RequestMapping("edit")
    public void editCategoryByParent(Category category){

        int i = this.categoryService.editCategoryByParent(category);

    }

}
